﻿using FC.ERP.TMom.Api.AppHandlers.Commands.EssentialDatas.FactoryManages.Lines;
using FC.ERP.TMom.Api.DTOs;
using FC.ERP.TMom.Domain;
using FC.ERP.TMom.ErrorCode;
using FC.ERP.TMom.Infrastructure.Implementes;
using FC.ERP.TMom.Infrastructure.Interfaces;
using MediatR;

namespace FC.ERP.TMom.Api.AppHandlers.CommandHandlers.EssentialDatas.FactoryManages.Lines
{
    public class WorkShopCommandHandler : IRequestHandler<WorkShopCommand, APIResult<List<LineDTO>>>
    {
        private readonly IBaseRepository<Line> linerepository;
        public WorkShopCommandHandler(IBaseRepository<Line> linerepository)
        {
            this.linerepository = linerepository;
        }
        public Task<APIResult<List<LineDTO>>> Handle(WorkShopCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<LineDTO>> result = new APIResult<List<LineDTO>>();
            result.Code=ResultCode.查询成功;
            result.Message=ResultCode.查询成功.ToString();
            var list = from a in linerepository.GetAll()
                       select new LineDTO
                       {
                           LineId = a.LineId,
                           LineName = a.LineName
                       };
            result.Data = list.ToList();
            return Task.FromResult(result);
        }
    }
}
